Cloud Design Patterns
About the Examples
|
This document describes the examples that illustrate the scenarios described in the guide Cloud Design Patterns (see http://aka.ms/Cloud-Design-Patterns). Each example is a Microsoft Visual Studio 2012 project that you can compile and run.
Before you start
Ensure that you have installed all of the software prerequisites. For details see the Release Notes.
Each example is a separate project. The folders of the examples also contain code snippets that demonstrate some of the patterns in the guide. These are not projects that can be run, but are included so that you can easily view and reuse the code in your own solutions.
The examples demonstrate operational aspects of applications running in Windows Azure. Therefore, you will need to use the diagnostics tools in order to understand how each code sample works. You must ensure that the web and worker roles in each solution are configured to use the diagnostics mechanism. If not, you will not see the trace information generated by each example.
Running the Examples
You can run all of the examples locally in the Visual Studio Windows Azure emulator. You can also run most of the examples by deploying them to a Windows Azure Cloud Service.
Configuring Service Bus for the Examples
Some of the examples use a Windows Azure Service Bus to send and receive messages. Check the details of each example shown below to see if this is required. Where it is required. you must:
About the Examples
Each example is a separate project within the solution. The folders of the solution also contain code snippets that demonstrate some of the patterns in the guide. These are not projects that can be run, but are included so that you can easily view and reuse the code in your own solutions.
The examples you can run are:
The code snippets for other patterns can be found in the root folder of the examples.
Competing Consumers. This example contains two components: the Sender worker role is responsible for sending messages to a Service Bus queue, and the Receiver worker role retrieves messages from the queue and processes them. The Receiver worker role is configured to run with two instances to simulate competition between consumers.
Compute Resource Consolidation. This example shows how you can consolidate several separate and distinct tasks into a single worker role. There are no additional requirements for running this example.
External Configuration Store. This example shows a mechanism for storing configuration settings in an external store instead of using configuration files. In this example, settings are stored in Windows Azure Blob Storage. The blob containing the configuration information is monitored by an instance of the ExternalConfigurationManager class. When the ExternalConfigurationManager object detects a change in the configuration store, it notifies the application of the change.
Health Endpoint Monitoring. This example shows how you can set up a web endpoint that checks the health of dependent services by returning appropriate status codes. The endpoints are designed to be consumed by a watchdog monitoring service such as Windows Azure Endpoint Monitoring, but you can open and invoke the endpoint operations from a browser to see the results. You can also deploy and configure your own endpoint monitoring tool of choice to send requests to the service operations and analyze the responses received.
Leader Election. This example shows how a worker role instance can become a leader among a group of peer instances. The leader can then perform tasks that coordinate and control the other instances; these tasks should be performed by only one instance of the worker role. The leader is elected by acquiring a blob lease. There are no additional requirements for running this example.
Pipes and Filters. This example contains two filters that could perform some part of the overall processing for a task. The two filters are combined into a pipeline; the output of one filter is passed as the input to the next. The filters are implemented as separate worker roles and a Windows Azure Service Bus queue provides the infrastructure that acts as the pipe.
Priority Queue. This example shows how you can implement priority queues by using Service Bus Topics and Subscriptions. A worker role is responsible for sending messages to a topic. It assigns a priority to each message. The receiving worker roles read messages from subscriptions that have the corresponding priority. In the example, The PriorityQueue.High worker role runs with two instances, whereas the PriorityQueue.Low worker runs only with one. This ensures that high priority messages are read from the queue more quickly than low priority messages.
Runtime Reconfiguration. This example shows how a change in the settings of a Cloud Service can be applied without restarting the web or worker role. The relevant code is in the files Global.asax.cs and WebRole.cs.
Static Content Hosting. This example shows how to reference static content from a publicly accessible storage service. The example contains a Windows Azure web role, which hosts a web application that references JavaScript files and images deployed to a Windows Azure storage account. This type of content is typically deployed to the storage account as part of the application deployment process. However, to simplify the example, these files are deployed to the storage account when the application starts up.
The JavaScript and stylesheet content is referenced in the file App_Start\BundleConfig.cs by using a CDN URL. The image content is referenced in the file Views\Home\Index.cshtml. The URLs are generated by an HTML helper class implemented in the file StaticContentUrlHtmlHelper.cs.
When running the application in release mode, you should note that these static resources are served out of the storage account, as opposed to being delivered by the application server.
Valet Key. This example shows how a client application can obtain a shared access signature with the necessary permissions to write directly to blob storage. For simplicity, this sample focuses on the mechanism to obtain and consume a valet key and does not show how to implement authentication or secure communications.